home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / disk / upcopy60.zip / UMAIN.C00 < prev    next >
Text File  |  1996-08-21  |  16KB  |  484 lines

  1. /*
  2. *               ╔════════════════════════════════════════╗
  3. *               ║                UPCOPY                  ║
  4. *               ║   Copyright (c) 1994-96 L.I.Williams   ║
  5. *               ║          All rights reserved           ║
  6. *               ║   Issue 6.0             Date: 22Aug96  ║
  7. *               ╚════════════════════════════════════════╝
  8. *
  9. *~    UMAIN.C00
  10. *    .C00 9-FEB-94 Iss 0.1 Created by LIW
  11. *~    Entry point main etc.
  12. *~    This UPCOPY source code module is provided for interest mainly
  13. *~    It's the parsing of the command parameters
  14. *~    It handles options almost anywhere, better than some
  15. *~
  16. */
  17. /************************************************************************
  18. * HISTORY:
  19. * Date      Iss  Who Comment
  20. * 09-FEB-94 0.1  LIW Created
  21. * 08-MAR-94 1.1  LIW LIW nagware
  22. * 29-MAR-94 2.0  LIW U001 Files system or hidden ignored, read-only skipped
  23. * 29-MAR-94 2.0  LIW U002 /R option to overwrite read-only
  24. * 29-MAR-94 2.0  LIW U003 Add header
  25. * 30-MAR-94 2.0  LIW U006 Fix *.*
  26. * 30-MAR-94 2.0  LIW U007 Show what is happening with /y
  27. * 30-MAR-94 2.0  LIW U008 Use term file(s) specified not path 
  28. * 30-MAR-94 2.0  LIW U009 Put message ... New file, no version here
  29. * 30-MAR-94 2.0  LIW U010 /N only new, /-N only common
  30. * 30-MAR-94 2.0  LIW U015 Take out text file detector
  31. * 30-MAR-94 2.0  LIW U016 /e and /o options
  32. * 02-APR-94 2.0  LIW U017 Change /-c to /c
  33. * 27-JUN-94 2.1  LIW U018 /y should not override /f
  34. * 02-AUG-94 3.0  LIW U020 Create directory
  35. * 09-AUG-94 3.0  LIW U021 Add /s option
  36. * 18-MAY-95 3.0  LIW U021 Complete /s. Create USCAN
  37. * 24-MAY-95 3.0  LIW U037 /q as well as /-d
  38. * 01-JUN-95 3.0  LIW U038 disable shareware /s with message
  39. * 18-JUN-95 4.0  LIW      Windowed stuff
  40. * 27-JUL-95 4.1  DE  U047-U050 Path problems
  41. * 06-AUG-95 4.1  LIW U054 root directory problem
  42. * 12-SEP-95 4.1  LIW U077 header with UPCOPY /b     
  43. * 19-SEP-95 4.1  LIW U083 Full stop on registered to message
  44. * 19-SEP-95 4.1  LIW U078 allow up to 9 levels and error
  45. * 21-SEP-95 4.1  LIW U085 unset options in parse
  46. * 01-FEB-96 5.0  LIW U106 Keycode registration
  47. * 26-FEB-96 5.0  LIW U110 Keyfile only registration
  48. * 29-MAR-96 5.0b LIW U118 /cd common directories option
  49. * 30-MAR-96 5.0b LIW U119 disk specified as target
  50. * 19-MAY-96 5.1  LIW U123 remove disk specified as target again
  51. * 06-AUG-96 6.0  LIW U149 copy if size or attributes changed
  52. * 14-AUG-96 6.0  LIW U058 remove duplicate from target /ec
  53. * 21-AUG-96 6.0  LIW U136 + to specify same path 
  54. ***********************************************************************/
  55. /* Include files: */
  56. #include <stdio.h>
  57. #include <stdlib.h>
  58. #include <string.h>
  59. #include <conio.h>
  60. #include <process.h>
  61. #include <ctype.h>
  62. #include <dos.h>
  63. #include <io.h>
  64. #include <sys\types.h>
  65. #include <sys\utime.h>
  66. #include <sys\stat.h>
  67. #include <ext.h>
  68. #include <direct.h>
  69. #include <fcntl.h> 
  70. #include <graph.h>
  71. #include <setjmp.h>
  72.  
  73. #include "keyboard.h"
  74. #include "field.h"
  75. #include "mouse.h"
  76. #include "udef.h00"
  77. #include "uproto.h00"
  78. #include "window.h"                  /* Window type and window functions */
  79.  
  80. /***********************************************************************
  81. These are the main global variables which have to be compiled in
  82. somewhere so here will do
  83. ***********************************************************************/
  84. #include "uglob.h00"
  85.  
  86. /***********************************************************************
  87. *
  88. The _dos_getftime routine uses system call 0x57 to get the date and
  89. time that the file identified by handle was last written.  The date
  90. and time are returned in the words that date and time, respectively,
  91. point to.  The values appear in the DOS date and time format, which
  92. is:
  93.  
  94. Time Bits       Meaning
  95. 0-4            Seconds/2 (0-29)
  96. 5-10           Minutes (0-59)
  97. 11-15           Hours (0-23)
  98.  
  99. Date Bits       Meaning
  100. 0-4            Day (1-31)
  101. 5-8            Month (1-12)
  102. 9-15           Year (1980-2099)
  103.  
  104. Return Value
  105. If successful, the function returns 0.  Otherwise, it returns the DOS
  106. error code and sets errno to EBADF, indicating that an invalid file
  107. handle was passed. 
  108. *
  109. * Start of code.
  110. ***********************************************************************/
  111. void main(int argc, char *argv[])
  112. {
  113. read_ini(argc);            // U106
  114. header();                // U003
  115.  
  116. no_paths = parse(argc,argv);        // sort out command
  117.  
  118. if (no_paths != 0)        // parameters specified?
  119.   tostream = TRUE;        // yes, go to streamed i/o 
  120. if (bopt)            // /b option?
  121.   tostream = TRUE;        // yes, go to streamed i/o 
  122. if (wopt)            // /w option?
  123.   tostream = FALSE;        // yes, override, windowed i/o 
  124.  
  125. if (tostream)            // batch mode ?
  126.   {                // yes
  127.   fprintf(stderr,"\n%s\n",headmess);    // output header
  128.   if (no_paths == 0)        // no parameters?
  129.     explain();            // output help, terminates with leave
  130.   upcrun();            // do upcopy run
  131.   if (!sharemode)            // registered user thankyou
  132.     fprintf(stderr,"%s\n",tailmess);
  133.   leave(0);            // terminates batch mode
  134.   }
  135.  
  136. /* All that follows is in windowed mode */
  137. dismenu();        // do menued display, does its own exit
  138. }
  139.  
  140. /***********************************************************************
  141. An UPCOPY run
  142. ***********************************************************************/
  143. void upcrun(void)
  144. {
  145. char    buffer[80];        // working line store
  146.  
  147. if (makepaths(path1,path2,&parmp1,&parmp2,buffer)) // make full pathnames
  148.   error(buffer);        // error message and exit
  149.  
  150. if (compf && quest)        // U017
  151.   {
  152.   /* Check if FC is available */
  153.   _searchenv( "FC.EXE", "PATH", buffer );
  154.   if (!*buffer)
  155.     {
  156.     lprintf("\nWarning: Can't find DOS 'FC' file compare in PATH\n");
  157.     lprintf("Ignoring /c option\n");
  158.     compf = FALSE;        // U017
  159.     }
  160.   }
  161.  
  162. if (!quest && twoway && eraseable)    // U016
  163.   lprintf("\nNote. /e has no effect with /y unless /f is specified.\n");
  164. // \nWarning. New files in %s will be automatically erased.\n
  165. if (!quest && !twoway && eraseable)    // U016
  166.   lprintf(autoeramess,parmp2.full);
  167. checksub();                // no comment
  168.  
  169. /* Get the present working directory and drive */
  170. odr = _getdrive();
  171. if (getcwd( owd, _MAX_DIR ) == NULL)
  172.   error("Can't find current directory");
  173. outlog("Original dr,dir =%c,%s\n",odr+'@',owd);
  174.  
  175. if (dironly)            // /i option
  176.   {
  177.   diffend = FALSE;        // preset no differences found
  178.   summary = TRUE;        // no output
  179.   rlevel = 0;            // set recursion level
  180.   scandirs(&parmp1,&parmp2);    // look through dir's to output result
  181.   if (!diffend)            // no differences?
  182. // \nFile(s) specified are the same\n
  183.     lprintf(fsamess);        // U008
  184.   else
  185. // "\nSome file(s) specified are different\n
  186.     lprintf(fdifmess);
  187.   }
  188. else
  189.   {                // normal copying run
  190.   summary = FALSE;        // with copying
  191.   diffend = FALSE;        // preset no differences found
  192.   rlevel = 0;            // set recursion level
  193.   scandirs(&parmp1,&parmp2);    // look through dir's, copying etc
  194.   if (!noinfo)            // not /q option
  195.     {
  196. // \nChecking result ...\n"
  197.     lprintf(chkrmess);        // U008
  198.     summary = TRUE;        // no output
  199.     diffend = FALSE;        // preset no differences found
  200.     rlevel = 0;            // set recursion level
  201.     scandirs(&parmp1,&parmp2);    // look through dir's to double check
  202.     if (!diffend)        // no differences?
  203. // File(s) specified are now the same\n
  204.       lprintf(fasamess);    // U008
  205.     else
  206. // Some file(s) specified are still different\n
  207.       lprintf(fdifmess);     // U008
  208.     }
  209.   }
  210. }
  211.  
  212. /***********************************************************************
  213. * Sorts out command options etc
  214. ***********************************************************************/
  215. int parse(int argc, char *argv[])
  216. {
  217. int    i;        // working integer
  218. char    *arg;        // argument pointer
  219. int    chopt;        // option character found
  220. int    chopt1;        // another option character
  221. int    lno_paths;    // local number of file specifiers found
  222.  
  223. bopt = FALSE;        // preset no /b option
  224. wopt = FALSE;        // preset no /w option
  225.  
  226. // U085
  227. commononly = compf = eraseable = dironly = logging = FALSE;
  228. newonly = overold = noinfo = over_rdonly = subdirs = FALSE;
  229. helpout = noinfo = mirrcopy = FALSE;
  230.  
  231. twoway = quest = TRUE;
  232.  
  233. lno_paths = 0;        // preset no parms
  234. strcpy(path1,"